<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="搬砖 嵌入式">
<meta property="og:type" content="website">
<meta property="og:title" content="学无止境">
<meta property="og:url" content="http://example.com/page/6/index.html">
<meta property="og:site_name" content="学无止境">
<meta property="og:description" content="搬砖 嵌入式">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="xudonglei">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/page/6/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>学无止境</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">学无止境</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Do not bb, show me the example</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/11/13/Python%E4%B8%AD%E7%94%A8%E5%8C%85%E6%9D%A5%E7%AE%A1%E7%90%86%E5%A4%9A%E4%B8%AA%E6%A8%A1%E5%9D%97/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/11/13/Python%E4%B8%AD%E7%94%A8%E5%8C%85%E6%9D%A5%E7%AE%A1%E7%90%86%E5%A4%9A%E4%B8%AA%E6%A8%A1%E5%9D%97/" class="post-title-link" itemprop="url">Python中用包来管理多个模块</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-11-13 21:38:22" itemprop="dateCreated datePublished" datetime="2023-11-13T21:38:22+08:00">2023-11-13</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2023/11/13/Python%E4%B8%AD%E7%94%A8%E5%8C%85%E6%9D%A5%E7%AE%A1%E7%90%86%E5%A4%9A%E4%B8%AA%E6%A8%A1%E5%9D%97/" class="post-meta-item leancloud_visitors" data-flag-title="Python中用包来管理多个模块" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/11/13/Python%E4%B8%AD%E7%94%A8%E5%8C%85%E6%9D%A5%E7%AE%A1%E7%90%86%E5%A4%9A%E4%B8%AA%E6%A8%A1%E5%9D%97/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/11/13/Python%E4%B8%AD%E7%94%A8%E5%8C%85%E6%9D%A5%E7%AE%A1%E7%90%86%E5%A4%9A%E4%B8%AA%E6%A8%A1%E5%9D%97/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://blog.csdn.net/hh5820/article/details/89854683">https://blog.csdn.net/hh5820/article/details/89854683</a></p>
<p>​                            <a target="_blank" rel="noopener" href="http://www.360doc.com/content/20/0306/13/11881101_897219430.shtml">http://www.360doc.com/content/20/0306/13/11881101_897219430.shtml</a> </p>
<p>​        在Python中也提供了包的功能，可以使用包来管理多个模块。使用包的好处在于可以有效避免名字冲突，便于包的维护管理。Python 中的模块包可以通过路径导入模块。</p>
<h3 id="一、包的组成"><a href="#一、包的组成" class="headerlink" title="一、包的组成"></a>一、包的组成</h3><p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311132141934.png"></p>
<p>​        一个简单的 Python 包的目录组成如下图：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311132141997.png" style="zoom:80%;">

<p>​        在上图所示的包中，如果需要导入 B 目录中的 a.py 模块，则在 Python 中可以使用以下语句之一。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> A.B <span class="keyword">import</span> a  <span class="comment"># 使用 from 导入模块</span></span><br><span class="line"> </span><br><span class="line"><span class="keyword">import</span> A.B.a  <span class="comment"># 使用 import 导入模块</span></span><br></pre></td></tr></table></figure>
<p>​        有了包的概念就可以很好地解决模块查找路径的问题。只要将所有的模块放在当前目录中的某一文件夹内，然后在该文件夹中新建一个空的 “ _ _init__.py” 文件，就可以通过目录结构的层次导入所需的模块。而不必像前边的例子那样将子目录的路径添加到 sys.path 列表中。</p>
<h3 id="二、包的内部引用"><a href="#二、包的内部引用" class="headerlink" title="二、包的内部引用"></a>二、包的内部引用</h3><p>​        Python 包中的模块也可能需要相互引用。对于上图中所示的位于 C 目录中的 b.py，如果要引用同样位于 C 目录中的 a.py，则可以使用以下语句：import a</p>
<p>​        如果位于 C 目录中的 b.py，如果要引用同样位于 B 目录中的 a.py，则可以使用以下语句：from A.B import a</p>
<h3 id="三、包与模块，类，函数之间的关系"><a href="#三、包与模块，类，函数之间的关系" class="headerlink" title="三、包与模块，类，函数之间的关系"></a>三、包与模块，类，函数之间的关系</h3><p>​        在享受软件的强大和智能的同时，其背后与之对应的代码规模也越来越大。因此我们无法将所有的功能代码块都放在一个文件中去。于是我们根据功能进行拆分为一个个模块进行组织。当模块很多的时候，为了便于模块管理和防止模块重名，又引入了一个比模块更大的容器(包)来组织模多个块。</p>
<p>​        其实python的程序我们可以理解为有包，模块和模块中的函数和类组成。它们之间的关系如下图所示：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311132144115.jpg" style="zoom:80%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/11/12/Ciclop%20horus%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/11/12/Ciclop%20horus%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91/" class="post-title-link" itemprop="url">Ciclop horus源码编译</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-11-12 11:54:37" itemprop="dateCreated datePublished" datetime="2023-11-12T11:54:37+08:00">2023-11-12</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE/" itemprop="url" rel="index"><span itemprop="name">开源项目</span></a>
                </span>
            </span>

          
            <span id="/2023/11/12/Ciclop%20horus%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91/" class="post-meta-item leancloud_visitors" data-flag-title="Ciclop horus源码编译" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/11/12/Ciclop%20horus%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/11/12/Ciclop%20horus%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        （1）在anaconda里yi面创建一个干净的环境，网上有人说要用python2：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311121154959.png"></p>
<p>​        （2）安装wxpython</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311121159428.png" style="zoom:80%;">

<p>并看下安装的这个版本是多少：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311121200617.png" style="zoom:67%;">

<p>​        后来发现安装这个4.0.4的版本后面会报错，有一个函数显示没有，看网友说的，好像是版本的问题，建议使用3.0的版本。所以到 <a target="_blank" rel="noopener" href="https://www.lfd.uci.edu/~gohlke/pythonlibs%E7%BD%91%E7%AB%99%E4%B8%AD%E6%89%BE%E5%88%B0%E7%9B%B8%E5%BA%943.0%E7%89%88%E6%9C%AC%E7%9A%84%E5%AE%89%E8%A3%85%E5%8C%85%E6%9D%A5%E5%AE%89%E8%A3%85%EF%BC%9A">https://www.lfd.uci.edu/~gohlke/pythonlibs网站中找到相应3.0版本的安装包来安装：</a></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311121911272.png" style="zoom:80%;">

<p>​        但是最后依然会报错：No module named wx，后来网上找到了相应的解决方法，并且实测有用：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311121913964.png" style="zoom:80%;">

<p>​        （3）安装opencv-python</p>
<p>​        使用conda安装，没有成功。所以改成离线安装，去下面这网站：<a target="_blank" rel="noopener" href="https://pypi.tuna.tsinghua.edu.cn/simple/opencv-python/">https://pypi.tuna.tsinghua.edu.cn/simple/opencv-python/</a> 下载了文件opencv_python-3.4.7.28-cp27-cp27m-win_amd64</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311121352372.png" style="zoom:80%;">

<p>​    （4）安装opengl库</p>
<p>​        到 <a target="_blank" rel="noopener" href="https://www.lfd.uci.edu/~gohlke/pythonlibs/">https://www.lfd.uci.edu/~gohlke/pythonlibs/</a> 中找到 amd64的安装包，一定要下python2的。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311121405636.png" style="zoom:60%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311121409324.png" style="zoom:80%;">

<p>​    （5）安装serial库</p>
<p>​        conda install pyserial</p>
<p>​    （6）安装scipy, matplotlib库</p>
<p>​        conda install scipy,    conda install matplotlib</p>
<p>​        环境安装的差不多，开始运行程序，结果报错，如下：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311121925162.png" style="zoom:80%;">

<p>​        报错的原因是因为：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311121927314.png" style="zoom:67%;">

<p>​        将axisbg这个参数名称改成facecolor即可。        </p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/11/11/python%E9%87%8C%E7%9A%84super().__init__()%E6%9C%89%E4%BB%80%E4%B9%88%E4%BD%9C%E7%94%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/11/11/python%E9%87%8C%E7%9A%84super().__init__()%E6%9C%89%E4%BB%80%E4%B9%88%E4%BD%9C%E7%94%A8/" class="post-title-link" itemprop="url">python里的super().__init__()有什么作用</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-11-11 22:27:12" itemprop="dateCreated datePublished" datetime="2023-11-11T22:27:12+08:00">2023-11-11</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2023/11/11/python%E9%87%8C%E7%9A%84super().__init__()%E6%9C%89%E4%BB%80%E4%B9%88%E4%BD%9C%E7%94%A8/" class="post-meta-item leancloud_visitors" data-flag-title="python里的super().__init__()有什么作用" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/11/11/python%E9%87%8C%E7%9A%84super().__init__()%E6%9C%89%E4%BB%80%E4%B9%88%E4%BD%9C%E7%94%A8/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/11/11/python%E9%87%8C%E7%9A%84super().__init__()%E6%9C%89%E4%BB%80%E4%B9%88%E4%BD%9C%E7%94%A8/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://blog.csdn.net/cnds123/article/details/127623653?spm=1001.2101.3001.6650.11&amp;utm_medium=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-11-127623653-blog-131629523.235%5Ev38%5Epc_relevant_anti_vip&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-11-127623653-blog-131629523.235%5Ev38%5Epc_relevant_anti_vip&amp;utm_relevant_index=13">https://blog.csdn.net/cnds123/article/details/127623653?spm=1001.2101.3001.6650.11&amp;utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-11-127623653-blog-131629523.235%5Ev38%5Epc_relevant_anti_vip&amp;depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-11-127623653-blog-131629523.235%5Ev38%5Epc_relevant_anti_vip&amp;utm_relevant_index=13</a></p>
<p>​                            <a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_54708219/article/details/129323207">https://blog.csdn.net/qq_54708219/article/details/129323207</a></p>
<h3 id="先介绍init"><a href="#先介绍init" class="headerlink" title="先介绍init()"></a><strong>先介绍<strong>init</strong>()</strong></h3><p>​        在学习 Python 类的时候，总会碰见书上的类中有 _ <em>init</em> _()这样一个方法【注：特殊方法（魔法函数）之一：初始化方法，相当于其它语言的构造函数，故也称为构造方法】， _ _init__() 方法可以包含多个参数，但必须包含一个名为 self 的参数，且必须作为第一个参数。即便你不手动为类添加任何构造方法，在程序编译期间有一个默认构造函数由python隐式注入一个空的默认构造函数：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self</span>):</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># no body, does nothing.</span></span><br></pre></td></tr></table></figure>
<h3 id="现在介绍super"><a href="#现在介绍super" class="headerlink" title="现在介绍super()"></a>现在介绍super()</h3><p>​        super 有两个典型用例。 在具有单继承的类层级结构中，super 可用来引用父类而不必显式地指定它们的名称，从而令代码更易维护。 这种用法与其他编程语言中 super 的用法非常相似。</p>
<p>​        第二个用例是在动态执行环境中支持协作多重继承。</p>
<h3 id="看python里的super-init-有什么用"><a href="#看python里的super-init-有什么用" class="headerlink" title="看python里的super().init()有什么用"></a>看python里的super().init()有什么用</h3><p>​        没用super（A, self). _ _init__()时调用A的父类属性情况：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Root</span>(<span class="params"><span class="built_in">object</span></span>):</span> <span class="comment">#可不写object </span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self</span>):</span></span><br><span class="line">        self.x= <span class="string">&#x27;这是属性&#x27;</span></span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">fun</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="comment">#print(self.x) #调用属性出错</span></span><br><span class="line">        print(<span class="string">&#x27;这是方法&#x27;</span>)</span><br><span class="line">         </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>(<span class="params">Root</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;实例化时执行&#x27;</span>)</span><br><span class="line"> </span><br><span class="line">test = A()      <span class="comment">#实例化类</span></span><br><span class="line">test.fun()  <span class="comment">#调用方法出错</span></span><br><span class="line"><span class="comment">#test.x      #调用属性出错</span></span><br></pre></td></tr></table></figure>
<p>​        使用super（A, self). _ _init__()时调用A的父类的属性情况：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Root</span>(<span class="params"><span class="built_in">object</span></span>):</span> <span class="comment">#可不写object </span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self</span>):</span></span><br><span class="line">        self.x = <span class="string">&#x27;这是属性&#x27;</span></span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">fun</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self.x)</span><br><span class="line">        print(<span class="string">&#x27;这是方法&#x27;</span>)</span><br><span class="line"> </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>(<span class="params">Root</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="built_in">super</span>(A,self).__init__() <span class="comment">#可不写 A,self</span></span><br><span class="line">        print(<span class="string">&#x27;实例化时执行&#x27;</span>)</span><br><span class="line"> </span><br><span class="line">test = A()  <span class="comment"># 实例化类</span></span><br><span class="line">test.fun()  <span class="comment"># 调用方法</span></span><br><span class="line">test.x  <span class="comment"># 调用属性</span></span><br></pre></td></tr></table></figure>
<p>​        由此可知，super(). _ _init__()的作用也就显而易见了，就是执行父类的构造函数，使得我们能够调用父类的属性。</p>
<h3 id="再看例子-super-Net-self-init"><a href="#再看例子-super-Net-self-init" class="headerlink" title="再看例子:super(Net, self). _ _init__()"></a>再看例子:<strong>super(Net, self). _ _init__()</strong></h3><p>​        Python中的super(Net, self). _ <em>init</em> <em>()是指首先找到Net的父类（比如是类NNet），然后把类Net的对象self转换为类NNet的对象，然后“被转换”的类NNet对象调用自己的init函数，其实简单理解就是子类把父类的 _ _init</em> <em>()放到自己的 _ _init</em> _()当中，这样子类就有了父类的 _ _init__()的那些东西。</p>
<p>​        回过头来看看我们的我们最上面的代码，Seq2SeqEncoder类继承d2l.Encoder，super(Net, self). _ _init__()就是对继承自父类d2l.Encoder的属性进行初始化。而且是用d2l.Encoder的初始化方法来初始化继承的属性。也就是说，子类继承了父类的所有属性和方法，父类属性自然会用父类方法来进行初始化。</p>
<p>​        举个例子帮助大家理解：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Person</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self,name,gender</span>):</span></span><br><span class="line">        self.name = name</span><br><span class="line">        self.gender = gender</span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">printinfo</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self.name,self.gender)</span><br><span class="line"> </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Stu</span>(<span class="params">Person</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self,name,gender,school</span>):</span></span><br><span class="line">        <span class="built_in">super</span>(Stu, self).__init__(name,gender) <span class="comment"># 使用父类的初始化方法来初始化子类</span></span><br><span class="line">        self.school = school</span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">printinfo</span>(<span class="params">self</span>):</span> <span class="comment"># 对父类的printinfo方法进行重写</span></span><br><span class="line">        print(self.name,self.gender,self.school)</span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    stu = Stu(<span class="string">&#x27;djk&#x27;</span>,<span class="string">&#x27;man&#x27;</span>,<span class="string">&#x27;nwnu&#x27;</span>)</span><br><span class="line">    stu.printinfo()</span><br></pre></td></tr></table></figure>
<p>​        当然，如果初始化的逻辑与父类的不同，不使用父类的方法，自己重新初始化也是可以的。比如：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Person</span>(<span class="params"><span class="built_in">object</span></span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self,name,gender,age</span>):</span></span><br><span class="line">        self.name = name</span><br><span class="line">        self.gender = gender</span><br><span class="line">        self.age = age</span><br><span class="line"> </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Student</span>(<span class="params">Person</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self,name,gender,age,school,score</span>):</span></span><br><span class="line">        <span class="comment">#super(Student,self).__init__(name,gender,age)</span></span><br><span class="line">        self.name = name.upper()  </span><br><span class="line">        self.gender = gender.upper()</span><br><span class="line">        self.school = school</span><br><span class="line">        self.score = score</span><br><span class="line"> </span><br><span class="line">s = Student(<span class="string">&#x27;Alice&#x27;</span>,<span class="string">&#x27;female&#x27;</span>,<span class="number">18</span>,<span class="string">&#x27;Middle school&#x27;</span>,<span class="number">87</span>)</span><br><span class="line"><span class="built_in">print</span> s.school</span><br><span class="line"><span class="built_in">print</span> s.name</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/11/11/Python%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E7%BB%A7%E6%89%BF/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/11/11/Python%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E7%BB%A7%E6%89%BF/" class="post-title-link" itemprop="url">Python面向对象之继承</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-11-11 12:14:25" itemprop="dateCreated datePublished" datetime="2023-11-11T12:14:25+08:00">2023-11-11</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2023/11/11/Python%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E7%BB%A7%E6%89%BF/" class="post-meta-item leancloud_visitors" data-flag-title="Python面向对象之继承" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/11/11/Python%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E7%BB%A7%E6%89%BF/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/11/11/Python%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E4%B9%8B%E7%BB%A7%E6%89%BF/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://blog.csdn.net/m0_66881249/article/details/128772180">https://blog.csdn.net/m0_66881249/article/details/128772180</a></p>
<h3 id="继承"><a href="#继承" class="headerlink" title="继承"></a>继承</h3><p>​        继承可以使一个类能够使用被继承类的中的代码，即继承可以提高代码复用率，降低冗余性，提高开发效率。</p>
<p>​        通俗来讲，通过继承，我们可以实现一个类中即使没有定义某一个方法，但是只有其父类中具有该方法，就可以实现正常的调用（调用的是父类中的那个方法），完成一定功能，这就是继承。</p>
<p>​        当类对象与类对象之间存在相同的内容，并满足子类对应的事物为父类对应事物中的一种时，就可以考虑使用继承，来提高代码复用性。</p>
<h3 id="Python中的继承"><a href="#Python中的继承" class="headerlink" title="Python中的继承"></a>Python中的继承</h3><p>​        Python是支持多继承的，而且Python2和Python3在继承这一块内容有区别，Python2中如果一个类没有对被继承的类进行指定（即下面代码这种情况），就是一个经典类（通俗来说就是比较老，默认没啥方法）</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span>:</span></span><br><span class="line">    <span class="keyword">pass</span></span><br></pre></td></tr></table></figure>
<p>​        Python2中如果一个类对被继承的类进行了指定（即下面代码这种情况），就是一个新式类（通俗来讲就是具有一些比较NB的默认方法）</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span>(<span class="params"><span class="built_in">object</span></span>):</span></span><br><span class="line">    <span class="keyword">pass</span></span><br></pre></td></tr></table></figure>
<p>​        但是，在Python3中，一个类如果没有进行指定，默认继承了object类，即Python3中已经去除了经典类，全部都是新式类（既然全部都是新式类了，那也就没必要说啥新式不新式的了，统一都叫做类），都具有NB的默认方法。<br>​        即下面这三种写法是等效的</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span>:</span></span><br><span class="line">    <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span>():</span></span><br><span class="line">    <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span>(<span class="params"><span class="built_in">object</span></span>):</span></span><br><span class="line">    <span class="keyword">pass</span></span><br></pre></td></tr></table></figure>
<p>​        其实Python在使用类创建实例对象的时候，也是通过一个方法（名为: `_ <em>new</em> _ ）完成的，即没有这个方法，实例对象根本就不会被创建出来，而之前我直接在一点自定义类对象中写上pass，也可以创建实例对象成功，这其实就是因为，该类继承了object，而object类对象中是具有该方法的，于是进行实例化对象的时候，就会继承object类对象中的该方法，实现对象实例化，这就是继承机制发挥作用的一个案例。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span>:</span></span><br><span class="line">    <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line">ins = C()</span><br><span class="line">print(ins)</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出结果：&lt;__main__.C object at 0x000001EC9062AFD0&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="单继承"><a href="#单继承" class="headerlink" title="单继承"></a>单继承</h3><p>​        仅仅继承了一个类，代码中体现为一个类的括号中仅仅写了一个类名。</p>
<p>单继承的运作过程</p>
<p>​        对于一个类创建出来的实例对象，这个实例对象调用了实例方法，则解释器会先通过实例对象中的`_ _class__属性去寻找该实例对象的类中是否具有该方法（前面说过实例对象中是不存储方法id的，方法id都在类对象中）<br>​        如果没有，则通过该类中的类属性去寻找该类的父类中是否具有该方法，如果没有，则继续去寻找其父类，…最后如果在最顶层的object类中依旧没有找到，则抛出异常<br>​        在这一整个寻找过程中，在任意一个环节寻找到了同名的方法，则对该方法进行调用，并不再继续寻找下去。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self)</span><br><span class="line">        print(<span class="string">&#x27;A的func实例函数&#x27;</span>)</span><br><span class="line">   </span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">B</span>(<span class="params">A</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self)</span><br><span class="line">        print(<span class="string">&#x27;B的func实例函数&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span>(<span class="params">B</span>):</span></span><br><span class="line">    <span class="keyword">pass</span></span><br><span class="line">    </span><br><span class="line">ins = C()</span><br><span class="line">ins.func()</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出结果：</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">&lt;__main__.C object at 0x00000275312FA6D0&gt;</span></span><br><span class="line"><span class="string">B的func实例函数</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>
<h3 id="多继承"><a href="#多继承" class="headerlink" title="多继承"></a>多继承</h3><p>继承了两个及两个以上的类，代码中体现为一个类的括号中写了多个类名，中间使用逗号隔开</p>
<p>多继承的运作过程</p>
<p>​        会按照该类括号中的父类的排列顺序，即从左到右逐个进行查找，针对每一个父类的查找可以参考单继承的查找方式，即先找到排列在第一个的父类中是否具有该方法，再寻找该父类的父类是否具有该方法…<br>​        如果第一个父类中都没有找到同名方法，则开始对第二个父类进行查找…如果从所有的父类那里都无法找到同名方法，则抛出异常<br>​        和单继承一样，在这一整个寻找过程中，在任意一个环节寻找找到了同名的方法，则对该方法进行调用，并不再继续寻找下去</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self)</span><br><span class="line">        print(<span class="string">&#x27;A的func实例函数&#x27;</span>)</span><br><span class="line">   </span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">B</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self)</span><br><span class="line">        print(<span class="string">&#x27;B的func实例函数&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span>(<span class="params">B,A</span>):</span></span><br><span class="line">    <span class="keyword">pass</span></span><br><span class="line">    </span><br><span class="line">ins = C()</span><br><span class="line">ins.func()</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出结果：</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">&lt;__main__.C object at 0x000001A7DCDDAB20&gt;</span></span><br><span class="line"><span class="string">B的func实例函数</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>
<h3 id="方法重写"><a href="#方法重写" class="headerlink" title="方法重写"></a>方法重写</h3><p>​        如果子类对于继承自父类的某一个属性或者方法不满意，可以进行修改，而且即便对方法进行了修改，对父类及其他子类是没有任何影响的，即父类和父类的所有子类还是可以调用父类的原来的方法，仅仅就是本类和本类的子类的同名方法被修改了而已</p>
<p>​        其实从上面继承机制的角度来看方法重写，就比较好理解了，这就是利用继承的查找机制实现的嘛，根本就没有什么新东西，子类的方法被重写，就是子类创建了一个同名的方法，当子类和子类的实例对象调用该方法的时候，就会执行继承的查找机制，<strong>当查找到该子类空间的时候，此时就会发现这个同名的方法，就会立即调用该方法，而且不会去父类中继续查找</strong>，而针对父类和其他没有进行该方法重写的子类来说，没有进行方法重写，在继承查找过程中就还是会去调用父类中定义的方法，即沿用父类中的代码，这就是所谓的方法重写的本质</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self)</span><br><span class="line">        print(<span class="string">&#x27;A的func实例函数&#x27;</span>)</span><br><span class="line">   </span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">B</span>(<span class="params">A</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self)</span><br><span class="line">        print(<span class="string">&#x27;B重写后的func实例函数&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    </span><br><span class="line">ins = B()</span><br><span class="line">ins.func()</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出结果：</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">&lt;__main__.B object at 0x00000219992AACD0&gt;</span></span><br><span class="line"><span class="string">B重写后的func实例函数</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>
<p>​        我们经常对一个对象的__init__初始化方法进行方法重写<br>​        值得一提的是，其实Python中的运算符的计算就是通过调用类对象中的方法完成的，所以如果对这些与运算符对应的方法进行重写，就会导致运算机制发生改变，而这种通过重写方法来改变机制的过程，对于运算符来说，称为运算符重载</p>
<h3 id="super方法"><a href="#super方法" class="headerlink" title="super方法"></a>super方法</h3><p>​        很多情况下，父类的方法并不是完全没有利用价值，即可能在方法重写以后，依旧要调用父类的方法进行一个补充，而此时子类就可以使用super方法去调用父类中定义的任意方法，即使在该子类中该方法被重写过了。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self)</span><br><span class="line">        print(<span class="string">&#x27;A的func实例函数&#x27;</span>)</span><br><span class="line">   </span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">B</span>(<span class="params">A</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self)</span><br><span class="line">        <span class="built_in">super</span>().func()		<span class="comment">#使用super方法进行父类A的func实例对象的调用</span></span><br><span class="line">        print(<span class="string">&#x27;B重写后的func实例函数&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    </span><br><span class="line">ins = B()</span><br><span class="line">ins.func()</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出结果：</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">&lt;__main__.B object at 0x000001E7B544AB20&gt;</span></span><br><span class="line"><span class="string">&lt;__main__.B object at 0x000001E7B544AB20&gt;</span></span><br><span class="line"><span class="string">A的func实例函数</span></span><br><span class="line"><span class="string">B重写后的func实例函数</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>
<p>​        一个实例方法是可以使用类对象进行调用的，只不过，此时实例方法不会自动传入实参（即一个实例对象的引用），如果需要使用实例对象的话，我们要手动传入一个实例对象</p>
<p>​        其实上面这个使用super的代码和下面这个不使用super的代码是等效的</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self)</span><br><span class="line">        print(<span class="string">&#x27;A的func实例函数&#x27;</span>)</span><br><span class="line">   </span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">B</span>(<span class="params">A</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(self)</span><br><span class="line">        A.func(self)        <span class="comment">#通过父类A直接调用其实例方法，注意要手动传入一个实例对象的引用</span></span><br><span class="line">        print(<span class="string">&#x27;B重写后的func实例函数&#x27;</span>)</span><br><span class="line"></span><br><span class="line">    </span><br><span class="line">ins = B()</span><br><span class="line">ins.func()</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出结果：</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">&lt;__main__.B object at 0x0000015B33DFACD0&gt;</span></span><br><span class="line"><span class="string">&lt;__main__.B object at 0x0000015B33DFACD0&gt;</span></span><br><span class="line"><span class="string">A的func实例函数</span></span><br><span class="line"><span class="string">B重写后的func实例函数</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>
<p>​        super方法的妙处其实要在下面这个案例中得以体现:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">parent</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;parent的func实例方法执行开始&#x27;</span>)</span><br><span class="line">        print(<span class="string">&#x27;parent的func实例方法执行完毕&#x27;</span>)</span><br><span class="line">   </span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">son1</span>(<span class="params">parent</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;son1重写后的func实例方法执行开始&#x27;</span>)</span><br><span class="line">        parent.func(self)</span><br><span class="line">        print(<span class="string">&#x27;son1重写后的func实例方法执行完毕&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">son2</span>(<span class="params">parent</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;son2重写后的func实例方法执行开始&#x27;</span>)</span><br><span class="line">        parent.func(self)</span><br><span class="line">        print(<span class="string">&#x27;son2重写后的func实例方法执行完毕&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">grandson</span>(<span class="params">son1, son2</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;grandson重写后的func实例方法执行开始&#x27;</span>)</span><br><span class="line">        son1.func(self)</span><br><span class="line">        son2.func(self)</span><br><span class="line">        print(<span class="string">&#x27;grandson重写后的func实例方法执行完毕&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">ins = grandson()</span><br><span class="line">ins.func()</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出结果：</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">grandson重写后的func实例方法执行开始</span></span><br><span class="line"><span class="string">son1重写后的func实例方法执行开始</span></span><br><span class="line"><span class="string">parent的func实例方法执行开始</span></span><br><span class="line"><span class="string">parent的func实例方法执行完毕</span></span><br><span class="line"><span class="string">son1重写后的func实例方法执行完毕</span></span><br><span class="line"><span class="string">son2重写后的func实例方法执行开始</span></span><br><span class="line"><span class="string">parent的func实例方法执行开始</span></span><br><span class="line"><span class="string">parent的func实例方法执行完毕</span></span><br><span class="line"><span class="string">son2重写后的func实例方法执行完毕</span></span><br><span class="line"><span class="string">grandson重写后的func实例方法执行完毕</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>
<p>​        这个案例中的继承图如图所示，为一个钻石型的图案</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311112211229.png" style="zoom:50%;">

<p>​        明显地，无论是仅仅看着代码进行分析，还是直接看打印结果，都可以分析出这么一个调用过程：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311112212963.png" style="zoom:70%;">

<p>​        明显，类对象parent中的func函数被调用了两次，想象一下这个过程中我们实际是要对一个数据进行一个初始化操作（在具体的项目中，确实很多时候就是要调用父类的方法进行属性的初始化操作），而且一般初始化要传入相应的参数的，比如看下面的简单的代码</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">parent</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;parent的__init__方法执行开始&#x27;</span>)</span><br><span class="line">        self.name = name</span><br><span class="line">        print(<span class="string">&#x27;parent的__init__方法执行完毕&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">son</span>(<span class="params">parent</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;son重写后的__init__方法执行开始&#x27;</span>)</span><br><span class="line">        parent.__init__(self, name)</span><br><span class="line">        print(<span class="string">&#x27;son重写后的__init__方法执行完毕&#x27;</span>)</span><br><span class="line"></span><br><span class="line">ins = son(<span class="string">&#x27;张三&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出结果：</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">son重写后的__init__方法执行开始</span></span><br><span class="line"><span class="string">parent的__init__方法执行开始</span></span><br><span class="line"><span class="string">parent的__init__方法执行完毕</span></span><br><span class="line"><span class="string">son重写后的__init__方法执行完毕</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>
<p>​        如果将上面那个钻石型继承关系的代码中的所有实例方法 _ <em>func</em> _ <em>都改为上面这个传入参数的</em> <em>init</em> <em>方法，就可以想象，在grandson中调用父类son1的</em> <em>init__的参数是完全没有起到任何作用的，全部都在son2的</em> <em>init</em> <em>方法调用后被覆盖掉了，即第一次对于父类son1的</em> <em>init</em> <em>的调用完全是无效的<br>再者，进行调用</em> <em>init</em> <em>方法进行实例对象的初始化的时候（一般在</em> _ <em>init</em> <em>方法中，都会调用父类的</em> _ <em>init</em> <em>方法），最终的那个类的 _ _init</em> _方法被调用了两次，这也是很奇怪的事情不是吗</p>
<p>​        而super方法的使用就可以解决这个问题（即最终的那个类的 _ _init__方法被调用了两次，导致前一次调用的操作完全失效，是无用功的问题）</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">parent</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;parent的func实例方法执行开始&#x27;</span>)</span><br><span class="line">        print(<span class="string">&#x27;parent的func实例方法执行完毕&#x27;</span>)</span><br><span class="line">   </span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">son1</span>(<span class="params">parent</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;son1重写后的func实例方法执行开始&#x27;</span>)</span><br><span class="line">        <span class="built_in">super</span>().func()</span><br><span class="line">        print(<span class="string">&#x27;son1重写后的func实例方法执行完毕&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">son2</span>(<span class="params">parent</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;son2重写后的func实例方法执行开始&#x27;</span>)</span><br><span class="line">        <span class="built_in">super</span>().func()</span><br><span class="line">        print(<span class="string">&#x27;son2重写后的func实例方法执行完毕&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">grandson</span>(<span class="params">son1, son2</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;grandson重写后的func实例方法执行开始&#x27;</span>)</span><br><span class="line">        <span class="built_in">super</span>().func()</span><br><span class="line">        print(<span class="string">&#x27;grandson重写后的func实例方法执行完毕&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">ins = grandson()</span><br><span class="line">ins.func()</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出结果：</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">grandson重写后的func实例方法执行开始</span></span><br><span class="line"><span class="string">son1重写后的func实例方法执行开始</span></span><br><span class="line"><span class="string">son2重写后的func实例方法执行开始</span></span><br><span class="line"><span class="string">parent的func实例方法执行开始</span></span><br><span class="line"><span class="string">parent的func实例方法执行完毕</span></span><br><span class="line"><span class="string">son2重写后的func实例方法执行完毕</span></span><br><span class="line"><span class="string">son1重写后的func实例方法执行完毕</span></span><br><span class="line"><span class="string">grandson重写后的func实例方法执行完毕</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>
<p>​        我知道读者看到这个结果大概率非常迷惑，但是至少我们可以发现一点，从输出结果来看，最终的那个类的 _ _init__方法只被调用了一次，非常符合我们的要求，即使用super方法貌似确实解决了我们上面的问题。</p>
<p>下面讲解super方法运行的原理</p>
<p>​        super使用的算法</p>
<p>​        使用super方法调用父类方法的时候，实际上会依据一个算法（即C3算法）自行计算出应该要调用哪一个父类的方法（从上面的输出结果来看，在调用son1的过程中调用了son2，所以实际上不一定是本类的父类）<br>​        实际上，我们不需要去理解C3算法的运行过程，只需要通过打印使用super方法的类对象的__mro__类属性即可知道super方法的调用顺序。</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">print(grandson.__mro__)</span><br><span class="line">(&lt;class &#x27;__main__.grandson&#x27;&gt;, &lt;class &#x27;__main__.son1&#x27;&gt;, &lt;class &#x27;__main__.son2&#x27;&gt;, &lt;class &#x27;__main__.parent&#x27;&gt;, &lt;class &#x27;object&#x27;&gt;)</span><br></pre></td></tr></table></figure>
<p>​        我们可以看到，这是一个元组类型对象，其中，每一个元素都是一个类对象<br>并且顺序依次为grandson、son1、son2、parent、object（明显为广度优先的查找原则）<br>对照上面代码的输出结果，我们惊奇地发现，每一次调用super. _ _init__方法，都是去调用该元组中的位于后面的类对象中的同名方法</p>
<p>​        实际上，类对象的 _ <em>mro</em> _类属性为一个元组（该元组也称为”作用链”），所有的元素都是类对象，super方法被调用的时候，会选择本类对象所在位置的后一个具有同名方法的类对象中的那个同名方法进行调用，如果执行代码的过程中，又遇到了一个super方法（无论和第一个super方法调用的方法名是否相同），则在原来的那个作用链中继续选择下一个类的同名方法进行调用，即后续所有的被嵌套调用的super方法，要选择调用哪个类对象的方法的时候，都要去查看调用第一个super方法的类对象的 _ _mro __ 类属性中各个类对象的排列顺序进行调用<br>​        接着我们康康super和 _ _mro__的官方定义</p>
<p>​        super被调用后，会返回一个对象，该对象是类的父类或兄弟类。super对于调用类中已被重写的父类方法非常用</p>
<p>​        类的 _ _mro__ 属性列出了getattr()和super()使用的搜索顺序。 _ _mro__属性是动态变化的，可以在继承层次结构更新时进行内容的变化</p>
<p>​        简单来说就是super方法的本质是使用类对象调用其中的同名方法，但是这个具体是哪一个类对象，要看 _ <em>mro__ 属性，</em> _ _mro __ 属性就是管这个事的，而且 _ _mro__属性是随着继承层次结构的变化而动态变化的。</p>
<p>​        其实super方法的返回的并不一定是 _ _mro__属性中本类的下一个类对象，严谨来说应该是下一个具有同名属性的类对象。</p>
<p>​        比如将上面那个代码中类对象son2的func函数的代码删除后的运行结果</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">parent</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;parent的func实例方法执行开始&#x27;</span>)</span><br><span class="line">        print(<span class="string">&#x27;parent的func实例方法执行完毕&#x27;</span>)</span><br><span class="line">   </span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">son1</span>(<span class="params">parent</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;son1重写后的func实例方法执行开始&#x27;</span>)</span><br><span class="line">        <span class="built_in">super</span>().func()</span><br><span class="line">        print(<span class="string">&#x27;son1重写后的func实例方法执行完毕&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">son2</span>(<span class="params">parent</span>):</span></span><br><span class="line">    <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">grandson</span>(<span class="params">son1, son2</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&#x27;grandson重写后的func实例方法执行开始&#x27;</span>)</span><br><span class="line">        <span class="built_in">super</span>().func()</span><br><span class="line">        print(<span class="string">&#x27;grandson重写后的func实例方法执行完毕&#x27;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">ins = grandson()</span><br><span class="line">print(grandson.__mro__)</span><br><span class="line">ins.func()</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出结果：</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">(&lt;class &#x27;__main__.grandson&#x27;&gt;, &lt;class &#x27;__main__.son1&#x27;&gt;, &lt;class &#x27;__main__.son2&#x27;&gt;, &lt;class &#x27;__main__.parent&#x27;&gt;, &lt;class &#x27;object&#x27;&gt;)</span></span><br><span class="line"><span class="string">grandson重写后的func实例方法执行开始</span></span><br><span class="line"><span class="string">son1重写后的func实例方法执行开始</span></span><br><span class="line"><span class="string">parent的func实例方法执行开始</span></span><br><span class="line"><span class="string">parent的func实例方法执行完毕</span></span><br><span class="line"><span class="string">son1重写后的func实例方法执行完毕</span></span><br><span class="line"><span class="string">grandson重写后的func实例方法执行完毕</span></span><br><span class="line"><span class="string">&quot;&quot;&quot;</span></span><br></pre></td></tr></table></figure>
<p>​        可以看到，grandson. _ _mro__的内容不变，但是在son1使用super方法的时候，并不是去调用son2的同名方法，而且son2中压根就没有这个名字的方法，于是son1会直接调用parent的同名方法</p>
<p>​        综上所述，super方法解决了在钻石型继承中父类方法最终会被调用多次，导致数据可能会被覆盖的问题。但是super方法的缺点在于，<strong>在多继承且为”钻石形继承”的情况下，写代码的时候，不知道最后在代码运行的时候，super方法使用的是哪一个类的方法（即代码的可读性差）</strong>；而且不同类的方法，形参数量极有可能不同，所以一般都会在调用super方法的时候全部写上不定长参数（即*args 与**kwargs）（进一步减低了代码的可读性）<br>​        当然，在单继承的情况下，super方法的使用不会有问题，而且可以明确知道super方法使用的是哪一个类的方法。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/11/10/Python%E4%B8%ADclass,%20class()%E5%92%8Cclass(object)%E7%9A%84%E5%8C%BA%E5%88%AB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/11/10/Python%E4%B8%ADclass,%20class()%E5%92%8Cclass(object)%E7%9A%84%E5%8C%BA%E5%88%AB/" class="post-title-link" itemprop="url">Python中class, class()和class(object)的区别</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-11-10 22:12:45" itemprop="dateCreated datePublished" datetime="2023-11-10T22:12:45+08:00">2023-11-10</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2023/11/10/Python%E4%B8%ADclass,%20class()%E5%92%8Cclass(object)%E7%9A%84%E5%8C%BA%E5%88%AB/" class="post-meta-item leancloud_visitors" data-flag-title="Python中class, class()和class(object)的区别" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/11/10/Python%E4%B8%ADclass,%20class()%E5%92%8Cclass(object)%E7%9A%84%E5%8C%BA%E5%88%AB/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/11/10/Python%E4%B8%ADclass,%20class()%E5%92%8Cclass(object)%E7%9A%84%E5%8C%BA%E5%88%AB/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://blog.csdn.net/u012856866/article/details/130942935">https://blog.csdn.net/u012856866/article/details/130942935</a></p>
<p>​        python2中写为如下两种形式都是不能继承object类的。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">class</span>:</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">class</span>():</span></span><br></pre></td></tr></table></figure>
<p>​        如果需要继承object类，需要写成如下形式：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">class</span>(<span class="params"><span class="built_in">object</span></span>):</span></span><br></pre></td></tr></table></figure>
<p>​        继承object类后，自己定义的类可拥有更多的属性。</p>
<p>​        python3中已经<strong>默认继承object类</strong>。即class, class()和class(object)三种写法都继承了object对象，具有多个可操作的对象，这些都是类中的高级特性。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></span><br><span class="line">    name = <span class="string">&quot;aa&quot;</span></span><br><span class="line">    </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">B</span>():</span></span><br><span class="line">    name = <span class="string">&quot;bb&quot;</span></span><br><span class="line">    </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span>(<span class="params"><span class="built_in">object</span></span>):</span></span><br><span class="line">    name = <span class="string">&quot;cc&quot;</span></span><br><span class="line"></span><br><span class="line">x = A()</span><br><span class="line"><span class="built_in">print</span> (<span class="string">&quot;A:&quot;</span>, <span class="built_in">dir</span>(x))</span><br><span class="line"><span class="comment"># A: [&#x27;__class__&#x27;, &#x27;__delattr__&#x27;, &#x27;__dict__&#x27;, &#x27;__dir__&#x27;, &#x27;__doc__&#x27;, &#x27;__eq__&#x27;, &#x27;__format__&#x27;, &#x27;__ge__&#x27;, &#x27;__getattribute__&#x27;, &#x27;__gt__&#x27;, &#x27;__hash__&#x27;, &#x27;__init__&#x27;, &#x27;__init_subclass__&#x27;, &#x27;__le__&#x27;, &#x27;__lt__&#x27;, &#x27;__module__&#x27;, &#x27;__ne__&#x27;, &#x27;__new__&#x27;, &#x27;__reduce__&#x27;, &#x27;__reduce_ex__&#x27;, &#x27;__repr__&#x27;, &#x27;__setattr__&#x27;, &#x27;__sizeof__&#x27;, &#x27;__str__&#x27;, &#x27;__subclasshook__&#x27;, &#x27;__weakref__&#x27;, &#x27;name&#x27;]</span></span><br><span class="line"></span><br><span class="line">y = B()</span><br><span class="line"><span class="built_in">print</span> (<span class="string">&quot;B:&quot;</span>, <span class="built_in">dir</span>(y))</span><br><span class="line"><span class="comment"># B: [&#x27;__class__&#x27;, &#x27;__delattr__&#x27;, &#x27;__dict__&#x27;, &#x27;__dir__&#x27;, &#x27;__doc__&#x27;, &#x27;__eq__&#x27;, &#x27;__format__&#x27;, &#x27;__ge__&#x27;, &#x27;__getattribute__&#x27;, &#x27;__gt__&#x27;, &#x27;__hash__&#x27;, &#x27;__init__&#x27;, &#x27;__init_subclass__&#x27;, &#x27;__le__&#x27;, &#x27;__lt__&#x27;, &#x27;__module__&#x27;, &#x27;__ne__&#x27;, &#x27;__new__&#x27;, &#x27;__reduce__&#x27;, &#x27;__reduce_ex__&#x27;, &#x27;__repr__&#x27;, &#x27;__setattr__&#x27;, &#x27;__sizeof__&#x27;, &#x27;__str__&#x27;, &#x27;__subclasshook__&#x27;, &#x27;__weakref__&#x27;, &#x27;name&#x27;]</span></span><br><span class="line"></span><br><span class="line">z = C()</span><br><span class="line"><span class="built_in">print</span> (<span class="string">&quot;C:&quot;</span>, <span class="built_in">dir</span>(y))</span><br><span class="line"><span class="comment"># C: [&#x27;__class__&#x27;, &#x27;__delattr__&#x27;, &#x27;__dict__&#x27;, &#x27;__dir__&#x27;, &#x27;__doc__&#x27;, &#x27;__eq__&#x27;, &#x27;__format__&#x27;, &#x27;__ge__&#x27;, &#x27;__getattribute__&#x27;, &#x27;__gt__&#x27;, &#x27;__hash__&#x27;, &#x27;__init__&#x27;, &#x27;__init_subclass__&#x27;, &#x27;__le__&#x27;, &#x27;__lt__&#x27;, &#x27;__module__&#x27;, &#x27;__ne__&#x27;, &#x27;__new__&#x27;, &#x27;__reduce__&#x27;, &#x27;__reduce_ex__&#x27;, &#x27;__repr__&#x27;, &#x27;__setattr__&#x27;, &#x27;__sizeof__&#x27;, &#x27;__str__&#x27;, &#x27;__subclasshook__&#x27;, &#x27;__weakref__&#x27;, &#x27;name&#x27;]</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">dir</span>()函数：Python的内置函数时，该函数会返回一个包含某个对象拥有的所有属性名和方法名的有序列表。</span><br></pre></td></tr></table></figure>
<p><strong>Object类</strong></p>
<p>​        所有类的<strong>父类</strong>，默认所有的类都继承至Object类</p>
<p>内置函数：</p>
<p><strong>new</strong>(cls, *args, **kwargs)</p>
<p>创建对象时自动调用的函数，主要作用是创建对象，给该对象分配空间，方便之后的的操作</p>
<p>该函数会返回创建出来的对象实体，一旦正常的返回实体后，调用初始化函数</p>
<p><strong>init</strong>(self)</p>
<p>初始化函数（构造函数），作用：给当前对象创建各类变量，并给变量赋初值，一般用于对象的初始设置，该函数没有返回值</p>
<p><strong>str</strong>(self)</p>
<p>对象描述函数，作用：返回当前对象的字符串类型的信息描述，一般用于对象的直接输出显示</p>
<p><strong>del</strong>(self)</p>
<p>删除该对象时会自动调用，一般用于工具型对象的资源回收<br>        例如：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Student</span>:</span></span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__new__</span>(<span class="params">cls, *args, **kwargs</span>):</span></span><br><span class="line">        print(<span class="string">&quot;创建对象时有自动调用的函数，如果当前函数没有返回对象，则不会再执行初始化函数了&quot;</span>)</span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">super</span>().__new__(cls)             <span class="comment"># 调用父类的创建对象的函数，进行当前对象的创建</span></span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age, sex</span>):</span></span><br><span class="line">        print(<span class="string">&quot;初始化函数，对象创建成功后自动调用，一般用于对象属性的赋值&quot;</span>)</span><br><span class="line">        self.name = name</span><br><span class="line">        self.age = age</span><br><span class="line">        self.sex = sex</span><br><span class="line"> </span><br><span class="line">    <span class="comment"># 返回当前对象的字符串描述</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__str__</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;我是&#123;&#125;，今年&#123;&#125;岁，是个&#123;&#125;的&quot;</span>.<span class="built_in">format</span>(self.name, self.age, self.sex)</span><br><span class="line"> </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__del__</span>(<span class="params">self</span>):</span></span><br><span class="line">        print(<span class="string">&quot;删除该对象时会自动调用该函数,一般用于工具类释放资源&quot;</span>)</span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    stu1 = Student(<span class="string">&#x27;张三&#x27;</span>, <span class="number">20</span>, <span class="string">&#x27;男&#x27;</span>)</span><br><span class="line">    print(stu1)                          <span class="comment"># 当输出对象时，输出该对象的字符串描述，自动调用__str__函数</span></span><br><span class="line">    <span class="keyword">del</span> stu1</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/11/10/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B9%8B%E5%8D%95%E4%BE%8B@singleton%E7%AE%80%E5%8D%95%E7%90%86%E8%A7%A3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/11/10/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B9%8B%E5%8D%95%E4%BE%8B@singleton%E7%AE%80%E5%8D%95%E7%90%86%E8%A7%A3/" class="post-title-link" itemprop="url">设计模式之单例@singleton简单理解</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-11-10 21:46:39" itemprop="dateCreated datePublished" datetime="2023-11-10T21:46:39+08:00">2023-11-10</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2023/11/10/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B9%8B%E5%8D%95%E4%BE%8B@singleton%E7%AE%80%E5%8D%95%E7%90%86%E8%A7%A3/" class="post-meta-item leancloud_visitors" data-flag-title="设计模式之单例@singleton简单理解" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/11/10/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B9%8B%E5%8D%95%E4%BE%8B@singleton%E7%AE%80%E5%8D%95%E7%90%86%E8%A7%A3/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/11/10/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B9%8B%E5%8D%95%E4%BE%8B@singleton%E7%AE%80%E5%8D%95%E7%90%86%E8%A7%A3/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_29924317/article/details/130921113">https://blog.csdn.net/qq_29924317/article/details/130921113</a></p>
<p>​         @singleton的实现原理是,在装饰的类中实现一个___new___方法,在该方法中判断是否已经存在实例,如果存在直接返回,否则创建实例。</p>
<p>​        装饰的类只有一个实例(单例),意思是说,对于一个装饰了@singleton的类,在整个程序运行期间,只会创建一个该类的实例。比如,我们有这样一个类:</p>
<p>@singleton<br>class Test:<br>    …<br>装饰了@singleton之后,无论我们调用Test()创建实例多少次,返回的 toujours 是一个实例:</p>
<p>t1 = Test()<br>t2 = Test()<br>print(t1 is t2) # True<br>t1和t2指向的都是同一个实例,因为@singleton实现了单例模式,确保Test类只有一个实例。</p>
<p>​        而如果不使用@singleton,每次调用Test()都会返回一个新实例:</p>
<p>class Test:<br>    …</p>
<p>t1 = Test()<br>t2 = Test()<br>print(t1 is t2) # False<br>        <strong>单例模式的目的是确保类只有一个实例,并提供全局访问点</strong>。这在一些场景下很有用,比如:- 数据库连接池:确保整个系统只有一个数据库连接实例</p>
<ul>
<li>文件系统:确保文件系统只初始化一次</li>
<li>配置文件:确保配置只读取一次所以,@singleton装饰器的作用是实现单例模式,使得装饰的类在程序运行期间只存在一个实例。这样可以简化全局状态的访问,并带来一定的资源利用优化。</li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/11/10/python%E7%B1%BB%E4%B8%AD%E7%9A%84self%E5%85%B3%E9%94%AE%E5%AD%97/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/11/10/python%E7%B1%BB%E4%B8%AD%E7%9A%84self%E5%85%B3%E9%94%AE%E5%AD%97/" class="post-title-link" itemprop="url">python类中的self关键字</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-11-10 21:36:32" itemprop="dateCreated datePublished" datetime="2023-11-10T21:36:32+08:00">2023-11-10</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2023/11/10/python%E7%B1%BB%E4%B8%AD%E7%9A%84self%E5%85%B3%E9%94%AE%E5%AD%97/" class="post-meta-item leancloud_visitors" data-flag-title="python类中的self关键字" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/11/10/python%E7%B1%BB%E4%B8%AD%E7%9A%84self%E5%85%B3%E9%94%AE%E5%AD%97/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/11/10/python%E7%B1%BB%E4%B8%AD%E7%9A%84self%E5%85%B3%E9%94%AE%E5%AD%97/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        原文地址：<a target="_blank" rel="noopener" href="https://www.zhihu.com/question/616719050/answer/3193138246?utm_id=0">https://www.zhihu.com/question/616719050/answer/3193138246?utm_id=0</a></p>
<p>​        在Python类中，self是一个习惯性用法，用于表示实例本身。在定义方法时，通常将第一个参数命名为self，通过它来访问和操作对象的属性。</p>
<p>​        例如：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MyClass</span>:</span>  </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, name, age</span>):</span>  </span><br><span class="line">        self.name = name  <span class="comment"># 这里self代表实例本身  </span></span><br><span class="line">        self.age = age  </span><br><span class="line">  </span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">print_info</span>(<span class="params">self</span>):</span>  </span><br><span class="line">        print(<span class="string">f&quot;Name: <span class="subst">&#123;self.name&#125;</span>, Age: <span class="subst">&#123;self.age&#125;</span>&quot;</span>)</span><br></pre></td></tr></table></figure>
<p>​        在这个例子中，self关键字代表了类的实例。当创建一个新的类实例时，比如my_instance = MyClass(‘Alice’, 25)，my_instance就是MyClass的一个实例。然后可以调用这个实例的print_info方法，方法中的self就是my_instance。</p>
<p>​        在调用方法时，Python会自动将实例（或者说是调用方法的对象）作为第一个参数传递给方法。这个参数就是我们通常说的self。例如：my_instance.print_info()  # 这里my_instance就是self</p>
<p>​        因此，<strong>self关键字在Python类中是用来表示实例本身</strong>，通过它可以访问和操作实例的属性。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/11/07/anaconda%E5%88%9B%E5%BB%BA%E5%A4%9A%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84python%E7%8E%AF%E5%A2%83/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/11/07/anaconda%E5%88%9B%E5%BB%BA%E5%A4%9A%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84python%E7%8E%AF%E5%A2%83/" class="post-title-link" itemprop="url">anaconda创建多个不同的python环境</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-11-07 14:23:11" itemprop="dateCreated datePublished" datetime="2023-11-07T14:23:11+08:00">2023-11-07</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2023/11/07/anaconda%E5%88%9B%E5%BB%BA%E5%A4%9A%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84python%E7%8E%AF%E5%A2%83/" class="post-meta-item leancloud_visitors" data-flag-title="anaconda创建多个不同的python环境" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/11/07/anaconda%E5%88%9B%E5%BB%BA%E5%A4%9A%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84python%E7%8E%AF%E5%A2%83/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/11/07/anaconda%E5%88%9B%E5%BB%BA%E5%A4%9A%E4%B8%AA%E4%B8%8D%E5%90%8C%E7%9A%84python%E7%8E%AF%E5%A2%83/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        anaconda里可以安装不同版本的python环境。其中有base的版本，除了与其他版本的文件位置不同，没有其他的特殊性。base版本的目录可能如下：E:\Anaconda；而其他版本的目录可能如下：E:\Anaconda\envs\环境名</p>
<p>​        查看你的系统当前已有的Python环境，执行命令：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20231107142735.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20231107142813.png" style="zoom:80%;">

<p>​        现在想添加一个新的环境，执行如下命令，命令中我制定了环境名称是base2，指定了Python版本是3.7，执行命令后，Conda会自动下载最新版的Python3.7，并自动部署:</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20231107143315.png" style="zoom:80%;">

<p>再次查看你的系统当前已有的Python环境，执行命令，从图中我们看到，这里多了一个名字为base2的Python环境。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20231107143436.png" style="zoom:80%;">

<p>​        切换Python环境到刚才新添加的base2，执行命令如下：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20231107143707.png" style="zoom:80%;">

<p>​        如果有些环境，不再使用，比如可通过执行命令：conda remove –name pyqt5 –all进行删除</p>
<p>​        <strong>pycharm中为工程设置新的环境</strong>：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/1微信截图_20231107145345.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/2微信截图_20231107145457.png" style="zoom:67%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20231107150245.png" style="zoom:67%;">

<p>​        后面开发的时候显示缺啥，就安装啥：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20231107150506.png" style="zoom:67%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/11/01/PCB%E8%AE%BE%E8%AE%A1%E4%B9%8B%E6%B3%AA%E6%BB%B4/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/11/01/PCB%E8%AE%BE%E8%AE%A1%E4%B9%8B%E6%B3%AA%E6%BB%B4/" class="post-title-link" itemprop="url">PCB设计之泪滴</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-11-01 20:24:31" itemprop="dateCreated datePublished" datetime="2023-11-01T20:24:31+08:00">2023-11-01</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%A1%AC%E4%BB%B6/" itemprop="url" rel="index"><span itemprop="name">硬件</span></a>
                </span>
            </span>

          
            <span id="/2023/11/01/PCB%E8%AE%BE%E8%AE%A1%E4%B9%8B%E6%B3%AA%E6%BB%B4/" class="post-meta-item leancloud_visitors" data-flag-title="PCB设计之泪滴" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/11/01/PCB%E8%AE%BE%E8%AE%A1%E4%B9%8B%E6%B3%AA%E6%BB%B4/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/11/01/PCB%E8%AE%BE%E8%AE%A1%E4%B9%8B%E6%B3%AA%E6%BB%B4/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        参考原文：<a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/486167680">https://zhuanlan.zhihu.com/p/486167680</a></p>
<p>​        简单来说：泪滴是固定导线与焊盘的机械结构，能使其更加稳固。大部分人在PCB设计时，对稳定要求高就会添加，要求不高便不加。</p>
<p>​        <strong>实际上，泪滴的作用不止于此。</strong></p>
<p>1.泪滴的存在，是为了避免电路板受到巨大外力的冲撞时，导线与焊盘或者导线与导孔的接触点断开。<br>2.泪滴可使PCB电路板显得更加美观。<br>3.焊接上，可以保护焊盘，避免多次焊接式焊盘的脱落。<br>4.生产时可以避免蚀刻不均，过孔偏位出现的裂缝等。<br>5.信号传输时平滑阻抗，减少阻抗的急剧跳变，避免高频信号传输时由于线宽突然变小而造成反射。<br>6.使走线与元件焊盘之间的连接趋于平稳过渡化。</p>
<p>​        在立创EDA专业版的使用过程中，<strong>添加泪滴流程</strong>：</p>
<p>​        顶部菜单栏 - 工具 - 泪滴，点击确定，即可生成泪滴</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311012029110.png" style="zoom:80%;">

<p>​        添加泪滴成功后效果图：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311012030965.png" style="zoom:50%;">

<p>​        未添加泪滴前：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311012030694.png" style="zoom:50%;">

<p><strong>泪滴的范围选项</strong><br>有两种，一种是全部选择，一种是只对选择。</p>
<p><strong>全部</strong><br>选择之后，会将整个PCB添加上泪滴。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311012031215.png" style="zoom:67%;">

<p><strong>只对选择</strong><br>只对选择上的焊盘添加泪滴。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202311012032717.png" style="zoom:67%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2023/10/31/%E5%98%89%E7%AB%8B%E5%88%9BPCB%E5%85%8D%E8%B4%B9%E4%B8%8B%E5%8D%95%E6%93%8D%E4%BD%9C%E6%B5%81%E7%A8%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2023/10/31/%E5%98%89%E7%AB%8B%E5%88%9BPCB%E5%85%8D%E8%B4%B9%E4%B8%8B%E5%8D%95%E6%93%8D%E4%BD%9C%E6%B5%81%E7%A8%8B/" class="post-title-link" itemprop="url">嘉立创PCB免费下单操作流程</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2023-10-31 22:29:32" itemprop="dateCreated datePublished" datetime="2023-10-31T22:29:32+08:00">2023-10-31</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%A1%AC%E4%BB%B6/" itemprop="url" rel="index"><span itemprop="name">硬件</span></a>
                </span>
            </span>

          
            <span id="/2023/10/31/%E5%98%89%E7%AB%8B%E5%88%9BPCB%E5%85%8D%E8%B4%B9%E4%B8%8B%E5%8D%95%E6%93%8D%E4%BD%9C%E6%B5%81%E7%A8%8B/" class="post-meta-item leancloud_visitors" data-flag-title="嘉立创PCB免费下单操作流程" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/10/31/%E5%98%89%E7%AB%8B%E5%88%9BPCB%E5%85%8D%E8%B4%B9%E4%B8%8B%E5%8D%95%E6%93%8D%E4%BD%9C%E6%B5%81%E7%A8%8B/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/10/31/%E5%98%89%E7%AB%8B%E5%88%9BPCB%E5%85%8D%E8%B4%B9%E4%B8%8B%E5%8D%95%E6%93%8D%E4%BD%9C%E6%B5%81%E7%A8%8B/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        参考原文：<a target="_blank" rel="noopener" href="https://blog.csdn.net/haigear/article/details/129843036">https://blog.csdn.net/haigear/article/details/129843036</a></p>
<p>​        在下单之前，必须首先下载一个下单助手，请记住，是必须，否则你领不到优惠券。<a target="_blank" rel="noopener" href="https://www.jlc.com/portal/appDownloadsWithConfig.html">https://www.jlc.com/portal/appDownloadsWithConfig.html</a></p>
<p>​        进入下单助手后，往下拉，靠下的部分有“更多的菜单”，连有优惠券中心，点击“免费券领取”，就是它，如果你想免费的话就点它了。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202310312303924.png" style="zoom:50%;">

<p>​        导出PCB制版文件：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202310312249927.png" style="zoom:80%;">

<p>​        下单并上传Gerber文件：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202310312305830.png" style="zoom:50%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202310312305945.png" style="zoom:67%;">

<p>​        最后付款的时候选择一下优惠券，就可以免费打样了：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202310312306234.png" style="zoom:67%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/5/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/5/">5</a><span class="page-number current">6</span><a class="page-number" href="/page/7/">7</a><span class="space">&hellip;</span><a class="page-number" href="/page/29/">29</a><a class="extend next" rel="next" href="/page/7/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">xudonglei</p>
  <div class="site-description" itemprop="description">搬砖 嵌入式</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">283</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">67</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xudonglei</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'BT0Qw9HcTpPv1a6cT1iDBXKz-gzGzoHsz',
      appKey     : 'LMCMh8v02JTMFAwKNRcgoizI',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
